package com.example.mapper;

import com.example.entity.Hengxiang;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface HengxiangMapper {

    // 根据id查询横向项目
    @Select("select * from Hengxiang where id = #{id}")
    Hengxiang selectById(Integer id);

    // 插入横向项目
    @Insert("insert into Hengxiang values (null,#{pname},#{cnumber},#{tamount},#{paname},#{pleader},#{eleader},now(),#{precords},#{participant},#{faccount},#{payment},now(),#{completionc},#{preport},now())")
    void insert(Hengxiang hengxiang);

    // 根据id更新横向项目信息
    @Update("<script> " + "update Hengxiang " + "<set> " + "<if test='pname != null'> " + "pname = #{pname}, " + "</if> " + "<if test='cnumber != null'> " + "cnumber = #{cnumber}, " + "</if> " + "<if test='tamount != null'> " + "tamount = #{tamount}, " + "</if> " + "<if test='paname != null'>" + "paname = #{paname}, " + "</if>" + "<if test='pleader != null'> " + "pleader = #{pleader}, " + "</if> " + "<if test='eleader != null'> " + "eleader = #{eleader}, " + "</if> " + "<if test='deadline != null'> " + "deadline = #{deadline}, " + "</if> " + "<if test='precords != null'> " + "precords= #{precords}, " + "</if> " + "<if test='participant != null'> " + "participant = #{participant}, " + "</if> " + "<if test='faccount != null'> " + "faccount = #{faccount}, " + "</if> " + "<if test='payment != null'> " + "payment = #{payment}, " + "</if> " + "<if test='completiont != null'> " + "completiont = #{completiont}, " + "</if> " + "<if test='completionc != null'> " + "completionc = #{completionc}, " + "</if> " + "<if test='preport != null'> " + "preport = #{preport}, " +"</if> " + "<if test='reportdate != null'> " + "reportdate = #{reportdate} " + "</if> " + "</set>" + "where id=#{id}" + "</script>")
    void updateById(Hengxiang hengxiang);

    // 根据id删除横向项目
    @Delete("delete from Hengxiang where id= #{id}")
    void deleteById(Integer id);

    // 根据条件查询所有横向项目
    @Select("<script>" + "select * from Hengxiang <where> "+ "<if test='id !=null'> " + "and id = #{id}"+ "</if> "+ "<if test='pname !=null'> " + "and pname like concat('%',#{pname},'%')"+ "</if> "+ "<if test='cnumber !=null'> " + "and cnumber like concat('%',#{cnumber},'%')"+ "</if> "+ "</where> "+ "</script>")
    List<Hengxiang> selectAll(Hengxiang hengxiang);
}
